package math
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import kim.math.ui.Ball;
	
		public class Ellipse extends Sprite
		{	
			private var a:int=200;//用于椭圆的球体
			private var b:int=80;
			private var c:int=60;
			private var container:Sprite=new Sprite();//创建容器
			private var _array:Array = null;
			
			public function Ellipse(centerX:Number, centerY:Number, _root:DisplayObject)
			{
				addChild(container);
				container.x=centerX;
				container.y=centerY;
				createEllipsoid();
				_root.transform.perspectiveProjection.fieldOfView=120;//初始化透视角度
				
				addEventListener(Event.ENTER_FRAME,Run);
			}
			
			//创建椭球体
			private function createEllipsoid ():void
			{
				this._array = [];
				for (var i:int=0; i<180; i+=5)
				{ //纬度
					for (var j:int=0; j<360; j+=5)
					{
						//经度
						var ball:Ball=new Ball();
						this._array.push(ball);
						container.addChild(ball);
						ball.x=a*Math.sin(i*Math.PI/180)*Math.cos(j*Math.PI/180);
						ball.z=b*Math.sin(i*Math.PI/180)*Math.sin(j*Math.PI/180);
						ball.y=c*Math.cos(i*Math.PI/180);
					}
				}
				
			}
			
			private function Run(event:Event):void
			{
				
				container.rotationY+=0.3;
				for each(var ball:Ball in this._array){
					ball.rotationY += 0.3;
				}
			}
		
			
		
	}
}